package com.sky.happygos.ui.activity.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.sky.happygos.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qqqqqqq on 2017/4/14.
 */
@EFragment(R.layout.fragment_order)
public class OrderF extends Fragment {

    @ViewById(R.id.vp_order)
    ViewPager viewPager;

    @ViewById(R.id.tab_order)
    TabLayout tabLayout;

    List<Fragment> list;
    List<String> listTitle;
    TabOrderAdapter adapter;



    @AfterViews
    public void init(){
        list = new ArrayList<>();
        listTitle = new ArrayList<>();
        listTitle.add("完成");
        listTitle.add("失败");
        listTitle.add("全部");
        OrderBoxF_ orderBoxs = new OrderBoxF_();
        orderBoxs.type = 1;
        OrderBoxF_ orderBoxf = new OrderBoxF_();
        orderBoxf.type = 2;
        OrderBoxF_ orderBoxa = new OrderBoxF_();
        orderBoxa.type = -1;
        list.add(orderBoxs);
        list.add(orderBoxf);
        list.add(orderBoxa);
        tabLayout.addTab(tabLayout.newTab().setText(listTitle.get(0)));
        tabLayout.addTab(tabLayout.newTab().setText(listTitle.get(1)));
        tabLayout.addTab(tabLayout.newTab().setText(listTitle.get(2)));


        adapter = new TabOrderAdapter(getChildFragmentManager(),list,listTitle);
        viewPager.setAdapter(adapter);

        tabLayout.setupWithViewPager(viewPager);
    }

    public class TabOrderAdapter extends FragmentPagerAdapter {

        private List<Fragment> list_fragment;                         //fragment列表
        private List<String> listTitle;



        public TabOrderAdapter(FragmentManager fm, List<Fragment> list_fragment,List<String> listTitle) {
            super(fm);
            this.list_fragment = list_fragment;
            this.listTitle = listTitle;
        }

        @Override
        public Fragment getItem(int position) {
            return list_fragment.get(position);
        }

        @Override
        public int getCount() {
            return list_fragment.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {

            return listTitle.get(position);
        }
    }
}
